//
//  CLReadLongPressCursorView.m
//  CLBrowser
//
//  Created by 梁慧聪 on 2022/8/16.
//

#import "CLReadLongPressCursorView.h"

@implementation CLReadLongPressCursorView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)setIsTorB:(BOOL)isTorB {
    _isTorB = isTorB;
    [self setNeedsDisplay];
}

- (void)setColor:(UIColor *)color {
    _color = color;
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(ctx, [self.color CGColor]);
    
    CGFloat rectW = self.bounds.size.width / 2;
    
    
    CGContextAddRect(ctx, CGRectMake((self.bounds.size.width - rectW) / 2, (self.isTorB ? 1 : 0), rectW, self.bounds.size.height - 1));
    
    CGContextFillPath(ctx);
    
    if (self.isTorB) {
        
        CGContextAddEllipseInRect(ctx, CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.width));
        
    }else{
        
        CGContextAddEllipseInRect(ctx, CGRectMake(0, self.bounds.size.height - self.bounds.size.width, self.bounds.size.width, self.bounds.size.width));
    }
    
    CGContextSetFillColorWithColor(ctx, [self.color CGColor]);
    
    CGContextFillPath(ctx);
    
}
@end
